package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.getTimer;
	
	import memory.MemoryRecovery;
	
	public class FPS extends Sprite
	{
		private var _fps:int=0;               //帧速
		private var frameCount:int=0;             //帧数
		private var oldTime:Number;
		private var currentTime:Number;
		public function FPS()
		{
			addEventListener(Event.ENTER_FRAME, onFrame);
		}
		public function get fps():int
		{
			return _fps;
		}
		private function onFrame(event:Event):void {
			frameCount++;
			if(frameCount==1) oldTime=getTimer();
			if(frameCount==12)
			{
				currentTime=getTimer();
				_fps=frameCount/((currentTime-oldTime)/1000);
				frameCount=0;
			}
		}
		public function dispose():void
		{
			MemoryRecovery.getInstance().gcFun(this,Event.ENTER_FRAME, onFrame);
		}
	}
}